<!--
 * @Author: 曹捷
 * @Date: 2019-12-18 15:55:43
 * @LastEditors: 曹捷
 * @LastEditTime: 2020-08-06 16:14:18
 * @Description: 嵌入网页
 -->
<template>
  <login-main @reload="reloadPage">
    <!-- https://uniapp.dcloud.io/static/web-view.html -->
    <web-view :src="webUrl" :webview-styles="webviewStyles" v-if="loading"></web-view>
    <obit-nodata v-else></obit-nodata>
  </login-main>
</template>

<script>
import util from '@/app-modules/utils/utils'
export default {
  data() {
    return {
      loading: false,
      option: {},
      webviewStyles: {
        progress: {
          color: '#FF3333',
        },
      },
      webUrl: '',
    }
  },
  onLoad(e) {
    this.option = e
    uni.setNavigationBarTitle({
      title: e.title,
    })
    this.init()
  },
  methods: {
    init() {
      let userInfo = uni.getStorageSync('userInfo')
      let param = {
        accessToken: userInfo.accessToken,
        userType: userInfo.userType,
        userId: userInfo.userId,
        personId: userInfo.personId,
      }
      param = Object.assign(param, this.option)
      delete param.title
      delete param.url
      this.webUrl = `${this.option.url}${util.util.urlEncode(param)}`
      console.log('TCL: init -> this.webUrl', this.webUrl)
    },
    reloadPage() {
      this.init()
      this.loading = true
    },
  },
  mounted() {
    this.$http.getHasLogin().then((res) => {
      this.loading = true
    })
  },
}
</script>

<style>
</style>